package com.lagou.controller;

import com.lagou.service.HelloService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.*;

@RestController
public class DemoController {

    @Reference
    private HelloService helloService;

    @RequestMapping("/test")
    public String test() {
        LinkedBlockingDeque linkedBlockingDeque = new LinkedBlockingDeque();
        Executor executor = new ThreadPoolExecutor(1, 20, 2000L,
                TimeUnit.MILLISECONDS, linkedBlockingDeque);

        int index = 0;
        while (index < 2100) {
            index++;

            executor.execute(new Runnable() {
                @Override
                public void run() {
                    helloService.sayHelloA("A");
                }
            });
            executor.execute(new Runnable() {
                @Override
                public void run() {
                    helloService.sayHelloB("B");
                }
            });
            executor.execute(new Runnable() {
                @Override
                public void run() {
                    helloService.sayHelloC("C");
                }
            });

        }

        return "";
    }

}
